/**
 * 总路由模块
 */
const express = require('express')
const router = express.Router()

// 引入 body-parser
const bodyparser = require('body-parser') 
router.use(bodyparser.urlencoded({extended: false}))
router.use(bodyparser.json())

// 引入 session 做验证登陆
const session = require('express-session')   
router.use(session({
   secret: 'key scd',
   saveUninitialized: false,
   resave: true,
   cookie: {maxAge: 1000*60*60*24} //1天
}))
// 导入 session 验证登陆中间件
const checklogin = require('../utils/checkLogin')

// 导入子路由
const login = require('../router/main/login')
const andmin = require('../router/main/admin')
const homeuser = require('../router/main/homeuser')
const store = require('../router/main/store')
const storegoods = require('../router/main/storegoods')
const userorder = require('../router/main/userorder')
const search = require('../router/main/search')
const adminpic = require('../router/main/adminpic')

// 注册路由
router.use('/admin', andmin)
router.use('/homeuser', homeuser)
router.use('/store', store)
router.use('/storegoods', storegoods)
router.use('/userorder', userorder)
router.use('/search', search)
router.use('/adminpic', adminpic)
router.use(login)

// 路由重定向
router.get('/', (req, res) => {
   res.redirect('/login')
})

// 导出路由模块
module.exports = router